<template>
  <van-popup
    :style="{ height: '40%' }"
    position="bottom"
    v-model="show"
  >
    <van-picker
      :columns="columns"
      @cancel="onCancel"
      @confirm="onConfirm"
      show-toolbar
      title="标题"
      :default-index="info.gender"
      :key="Date.now()"
    />
  </van-popup>
</template>

<script>
import { updateUserProfile } from "../../../network/user"
export default {
  name: "EditorGender",
  props:['info'],
  components: {},
  watch: {
  },
  data() {
    return {
      show: false,
      columns: ['男','女']
    };
  },
  created() {
  },
  mounted() {},
  methods: {
    isShow() {
      this.show = true;
    },
    onCancel() {
      this.show = false
    },
    //后台有问题，不能修改性别会失败
    async onConfirm(val,index) {
      if(this.info.gender !== index){
        const result = await updateUserProfile({
          gender:0
        })
        if (result.message === "OK") {
          this.info.gender = index;
          this.show = false;
          this.$toast.success("修改成功");
          return;
        }
        this.$toast.fail("修改失败");
      }
    }
  }
};
</script>

<style scoped lang="stylus" >
/deep/ .van-nav-bar
  background-color #fff !important

  .van-nav-bar__text
    color #576b95 !important

  .van-nav-bar__left
    .van-nav-bar__text
      color gray !important

  .van-nav-bar__title
    color #000 !important
</style>